<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>登入页面</title>
	</head>
	<body>
		用户名：<input type="text" name="" id="username" value="" onfocus="selectInput()" onblur="leaveInput()"/><br>
		密码：<input type="password" name="" id="pwd" value="" / onfocus="selectInput1()" onblur="leaveInput1()"><br>
		<button type="button" onclick="btnClick()">提交</button>
	</body>
	<script type="text/javascript">
		function selectInput()
		{
			console.log('用户在输入名称');
		}
		function leaveInput()
		{
			if(document.getElementById('username').value == '')
			{
				alert('没有输入用户名');
			}
		}
		function selectInput1()
		{
			console.log('用户在输入密码');
		}
		function leaveInput1()
		{
			if(document.getElementById('pwd').value == '')
			{
				alert('没有输入密码');
			}
		}
		function btnClick()
		{
			//if(document.getElementById('username').value == '')
			//{
			//	console.log('用户名为空');
			//}
			//else if(document.getElementById('pwd').value == '')
			//{
			//	console.log('密码为空');
			//}
			if(document.getElementById('username').value == '' && document.getElementById('pwd').value == '')
			{
				console.log('用户名和密码为空');
			}
			else if(document.getElementById('username').value == '')
			{
				console.log('用户名为空');
			}
			else if(document.getElementById('pwd').value == '')
			{
				console.log('密码为空');
			}
		}
	</script>
</html>
